public class Frame
{
	int x;
	int y;

	int w;	// full size
	int h;

	int fw;	// one frame size
	int fh;

	int index;	// image index

	static int x1,y1,x2,y2;

	static int cnt;

	boolean isFrammed;

	public Frame(int index,int x,int y,int w,int h,int fw,int fh)
	{
		this.index = index;
		this.x = x;
		this.y = y;
		this.w = w;
		this.h = h;
		this.fw = fw;
		this.fh = fh;

		isFrammed = (fw != w) || (fh != h) || (x != 0) || (y != 0);
	}

	void draw(int gx,int gy)
	{
		if (isFrammed)
		{
			x1 = gx;
			y1 = gy;
			x2 = fw;
			y2 = fh;
			if (x1 < 0)
			{
				x2 += x1;
				x1 = 0;
			}
			if (y1 < 0)
			{
				y2 += y1;
				y1 = 0;
			}
			Main.setClip(x1,y1,x2,y2);
			cnt++;
		}
		Main.drawImage(index,gx - x,gy - y); 
	}

	void draw(int gx,int gy,int num)
	{
		x1 = gx;
		y1 = gy;
		x2 = fw;
		y2 = fh;
		if (x1 < 0)
		{
			x2 += x1;
			x1 = 0;
		}
		if (y1 < 0)
		{
			y2 += y1;
			y1 = 0;
		}
		Main.setClip(x1,y1,x2,y2);
		Main.drawImage(index,gx - x - num * fw,gy - y);
		cnt++;
	}
	void draw(int gx,int gy,int cx,int cy,int cw,int ch)
	{
		x1 = gx > cx ? gx : cx;
		y1 = gy > cy ? gy : cy;
		x2 = gx + fw < (cx + cw) ? gx + fw : cx + cw;
		y2 = gy + fh < (cy + ch) ? gy + fh : cy + ch;

		x2 -= x1;
		y2 -= y1;

		// checks for Siemens
		if (x1 < 0)
		{
			x2 += x1;
			x1 = 0;
		}
		if (y1 < 0)
		{
			y2 += y1;
			y1 = 0;
		}
		// check for Motorola
		if (y1 + y2 >= gy)
		{
			Main.setClip(x1,y1,x2,y2);
			Main.drawImage(index,gx - x,gy - y);
			cnt++;
		}
	}
}

